package com.group.prescription.service.iml;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.commons.util.CommonStatus;
import com.group.commons.util.ResponseInfo;
import com.group.commons.util.ResponseStatus;
import com.group.prescription.dao.PrescriptionDao;

import com.group.prescription.entity.Prescription;
import com.group.prescription.service.PrescriptionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class PrescriptionImpl implements PrescriptionService {
    @Resource
    PrescriptionDao prescriptionDao;

    @Override
    public ResponseInfo deleteOne(int id) {
        int i= prescriptionDao.deleteOne(id);
        if(i>0){
            return  new ResponseInfo(200,"删除成功",i, ResponseStatus.SUCCESS);
        }
        return new ResponseInfo(400,"",i,ResponseStatus.FAILED);
    }

    @Override
    public ResponseInfo batchDeletes(List delList) {
        int i= prescriptionDao.batchDeletes(delList);
        if(i>0){
            return  new ResponseInfo(200,"删除成功",i, ResponseStatus.SUCCESS);
        }
        return new ResponseInfo(400,"",i,ResponseStatus.FAILED);
    }

    @Override
    public ResponseInfo findAll(Prescription prescription, int page, int pages) {
        PageHelper.startPage(page, pages);
        List<Prescription> prescriptionList = prescriptionDao.findAll(prescription);
        PageInfo<Prescription> prescriptionPageInfo = new PageInfo<>(prescriptionList);
        return  new ResponseInfo(200,"查询成功",prescriptionPageInfo, ResponseStatus.SUCCESS);
    }

    @Override
    public ResponseInfo findByStatus(CommonStatus commonStatus, int page, int pages) {
        Page<Prescription> objects = PageHelper.startPage(page, pages);
        List<Prescription> prescriptionList = prescriptionDao.findByStatus(commonStatus);
        PageInfo<Prescription> prescriptionPageInfo = new PageInfo<>(objects);
        return  new ResponseInfo(200,"查询成功",prescriptionPageInfo, ResponseStatus.SUCCESS);
    }
}
